package srzy.driver

import srzy.data.PublicData
import srzy.common.Logging
import srzy.module.CaseDeal
import srzy.common.Common
import srzy.diameter._
import srzy.socket._
import srzy.dao.DBUtil
import java.io.File
import srzy.common.Config
import scala.collection.mutable.ListBuffer

object Start7 extends Logging {

  def main(args: Array[String]): Unit = {
    deal
  }

  def deal = {
    val l = xml.XML.loadString(srzy.common.readFromFile("1.xml").mkString("\n"))
    val a1 = (l \ "traffic").head

    //    a1.child.map(x => {
    //      println("label:" + x.label)
    //      x.label match {
    //        case "send"    =>
    //        case "wait-ms" => println((x \\ "@value").head.text)
    //        case "db"      => println((x \ "sql").toList.head.text)
    //        case "shell"   =>
    //        case _         =>
    //      }
    //
    //      x
    //    }).mkString("\n-----\n")

    println(a1.child.toList.foldLeft(ListBuffer.empty[srzy.module.Action])((l, x) => {
      println("label:" + x.label)
      x.label match {
        case "send" =>
          //          l.append(new srzy.module.SendAction)
          l
        case "wait-ms" =>
          l.append(new srzy.module.WaitAction {
            val waitTime = Integer.parseInt((x \\ "@value").head.text)
          })
          l
        case "db" =>
          l.append(new srzy.module.DbOperAction {
            val source = (x \\ "@name").head.text
            val dbUtil = DBUtil(source)
            val sqlList = (x \ "sql").toList.map(x => x.text)
          })
          l

        case "shell" =>
          l.append(new srzy.module.ShellOperAction {
            val shell = x.text
          })
          l
        case _ => l
      }
    }))

  }
}

